<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="topicId" label="标题" show-overflow-tooltip>
        <template slot-scope="{ row }">
          <span class="txt-hover" @click="handleDetail(row)">
            {{ row.bbsTopic.title }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="sysClassify"
        label="分类"
        width="100"
        show-overflow-tooltip
      >
        <template slot-scope="{ row }">
          <span>{{ row.bbsTopic.sysClassify.name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="userName"
        label="作者"
        width="100"
        show-overflow-tooltip
      >
        <template slot-scope="{ row }">
          <span>{{ row.bbsTopic.sysUser.userName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="clickCount" label="浏览数" width="80">
        <template slot-scope="{ row }">
          <span>{{ row.bbsTopic.clickCount }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="收藏时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="160">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="success" size="mini" @click="handleDetail(row)"
              >详情</el-button
            >
            <el-popconfirm
              title="确定取消收藏吗？"
              @confirm="handleDelete(row)"
            >
              <el-button type="danger" slot="reference" size="mini">
                取消收藏
              </el-button>
            </el-popconfirm>
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        opt: 'collect',
        isAll: 'N',
        ctype: 1,
      },
      tableData: [],
      pageObj: {},
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    async getList() {
      let res = await this.$store.dispatch('queryBbsCollect', this.listQuery)
      this.tableData = res.data
      this.pageObj = res
    },
    handleDetail(row) {
      const URL = this.$router.resolve({
        name: 'bbs-detail',
        query: { id: row.topicId },
      })
      window.open(URL.href, '_blank')
    },
    async handleDelete(row) {
      let obj = {
        topicId: row.topicId,
        opt: 'collect',
        ctype: 1,
      }
      await this.$store.dispatch('cancelBbsCollect', obj)
      this.getList()
    },
  },
}
</script>
<style scoped lang="scss">
</style>